<?php
include 'wp-blog-header.php';
$uniqid = uniqid();
$param = $_GET['p'];
$param = decrypt($param,'1b2u3z4z5r6');
$param = explode('$',$param);
//echo "<pre>";
//print_r($param);
//exit();

$api_key = $param['0'];

if(!empty($api_key))
{
  $api_pod = new Pod('api');
  $api_pod->page = 1;
  $api_pod->search = 1;
  $api_pod->findRecords('id DESC', -1, "t.api_key ='$api_key'");
  $api_exists = $api_pod->getTotalRows();
  if($api_exists > 0)
  {
    while($api_pod->fetchRecord()){
      $client_name = $api_pod->get_field('name');
      $client_name = explode('_',$client_name);
      $client_name = $client_name[0];    
    }
  }
}

if($api_exists > 0)
{
  $par = preg_replace('/~/','-',$param['1']);
  $ex_par = explode('-',$par);
  $city = ucwords($ex_par['1']);
  
  $url = BUZZR_URL.'/api2/?t='.$par.'&items=10&format=json&apikey='.$api_key;
  $curl_json_output = buzzr_download_page($url);
  $json_decoded = json_decode($curl_json_output, true);
  
  $background = $param['3'];
  
  $width = $param['2'];
  
 /*
  echo "<pre>"; 
  print_r($json_decoded);
  echo "</pre>"; 
  exit();
  */
  ?>
<style>
  a{
    text-decoration: none;
  }
  
  img
  {  
    border-style: none;
    vertical-align: text-bottom;
  }
  
  #contentDiv_<?php echo $uniqid; ?>
  {
  float:left;
  -moz-border-radius: 10px;
  -webkit-border-radius: 10px;
  background:<?php echo $background; ?>;
  width:<?php echo $width; ?>;
  padding: 10px 5px;
  border:1px solid #DFDFDF;
  }
  
  #widget_logo_<?php echo $uniqid; ?>
  {
    padding-left: 10px;
  }
  
  #widget_logo_<?php echo $uniqid; ?> a{
    text-decoration: none;
  }
  
  #allDealsDiv_<?php echo $uniqid; ?>
  {
  -moz-border-radius: 10px;
  -webkit-border-radius: 10px;
  background: none repeat scroll 0 0 white;
  border: 1px solid #DFDFDF;
  height: 250px;
  margin: 10px;
  overflow: auto;
  padding-left: 5px;
  padding-right: 5px;
  }
  
  .item_<?php echo $uniqid; ?>
  {
  font-size: 12px;
  line-height: 21px;
  padding: 3px;
  border-bottom: 1px groove <?php echo $background; ?>;
  }
  
  #footer_note_<?php echo $uniqid; ?>
  {
  -moz-border-radius: 10px;
  -webkit-border-radius: 10px;
  background: none repeat scroll 0 0 white;
  float: right;
  font-size: 10px;
  line-height: 21px;
  padding: 0 5px;
  text-align: center;
  width: 103px;
  } 
</style>    
    <div id="contentDiv_<?php echo $uniqid; ?>">
      <div id="widget_logo_<?php echo $uniqid; ?>"><a target="_blank" href="http://buzzr.in?utm_source=API&utm_medium=API&utm_campaign=<?php echo urlencode($client_name); ?>&ref=<?php echo $param['4']; ?>"><img src="http://buzzr.in/wp-content/pfiles/images/buzzr_widget1.png" /></a><font size="3" color="white"><?php echo $city; ?> Offers</font></div>
        <div id="allDealsDiv_<?php echo $uniqid; ?>">    
        <?php
          foreach($json_decoded as $key=>$value)
          {
            $red_link = $value['offer_red_link'];
			if(empty($red_link)){
				$red_link = $value['offer_link'];
			}
			echo '<div id="item_'.$key.'" class="item_'.$uniqid.'"><a target="_blank" href="'.$red_link.'&ref='.$param['4'].'">'.stripslashes($value['offer_name']).'</a></div>';
          }
        ?>
        </div>
        <div id="footer_note_<?php echo $uniqid; ?>">Powered by <a target="_blank" href="http://buzzr.in?utm_source=API&utm_medium=API&utm_campaign=<?php echo urlencode($client_name); ?>&ref=<?php echo $param['4']; ?>">Buzzr.in</a></div>
    </div>
<?php
}
else
{
?>
<style>
  a{
    text-decoration: none;
  }
  
  img
  {  
    border-style: none;
  }
  
  #contentDiv_<?php echo $uniqid; ?>
  {
  float:left;
  -moz-border-radius: 10px;
  -webkit-border-radius: 10px;
  background: #000000;
  width: 250px;
  padding: 10px 5px;
  border:1px solid #DFDFDF;
  }
  
  #widget_logo_<?php echo $uniqid; ?>
  {
  padding-left: 10px;
  }
  
  #widget_logo_<?php echo $uniqid; ?> a{
    text-decoration: none;
  }
  
  #allDealsDiv_<?php echo $uniqid; ?>
  {
  -moz-border-radius: 10px;
  -webkit-border-radius: 10px;
  background: none repeat scroll 0 0 white;
  border: 1px solid #DFDFDF;
  height: 250px;
  margin: 10px;
  overflow: auto;
  padding-left: 5px;
  padding-right: 5px;
  }
  
  .item_<?php echo $uniqid; ?>
  {
  font-size: 12px;
  line-height: 21px;
  margin-top: 65px;
  padding: 10px;
  }
  
  #footer_note_<?php echo $uniqid; ?>
  {
  -moz-border-radius: 10px;
  -webkit-border-radius: 10px;
  background: none repeat scroll 0 0 white;
  float: right;
  font-size: 10px;
  line-height: 21px;
  padding: 0 5px;
  text-align: center;
  width: 103px;
  } 
</style> 

    <div id="contentDiv_<?php echo $uniqid; ?>">
      <div id="widget_logo_<?php echo $uniqid; ?>"><a target="_blank" href="http://buzzr.in?utm_source=API&utm_medium=API&utm_campaign=<?php echo urlencode($client_name); ?>"><img src="http://buzzr.in/wp-content/pfiles/images/buzzr_widget1.png" /></a></div>
        <div id="allDealsDiv_<?php echo $uniqid; ?>">    
          <?php
            echo '<div class="item_'.$uniqid.'"><a title="Contact Us" target="_blank" href="http://buzzr.in/contact-us?utm_source=API&utm_medium=API&utm_campaign='.urlencode($client_name).'">Sorry it there seems to be some problem with your API Key Please contact us on Buzzr.in<br />Thank You!</a></div>';
          ?>
        </div>
        <div id="footer_note_<?php echo $uniqid; ?>">Powered by <a target="_blank" href="http://buzzr.in?utm_source=API&utm_medium=API&utm_campaign=<?php echo urlencode($client_name); ?>">Buzzr.in</a></div>
    </div>
<?php
}
?>  